package zyg.yws.ywsthree;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener, CompoundButton.OnCheckedChangeListener,View.OnClickListener {
    RadioGroup num1;
    RadioButton num1_1;
    RadioButton num1_2;
    RadioGroup num2;
    RadioButton num2_1;
    RadioButton num2_2;
    RadioButton num2_3;
    RadioGroup num3;
    RadioButton num3_1;
    RadioButton num3_2;
    ArrayList<String> mainConsume;
    CheckBox num4_1;
    CheckBox num4_2;
    CheckBox num4_3;
    CheckBox num4_4;
    CheckBox num4_5;
    CheckBox num4_6;
    CheckBox num4_7;
    EditText num5;
    EditText num;
    Button tijiao;
    View tuichu;
    String daan1;String daan2;String daan3;
    @SuppressLint("WrongViewCast")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }
    public void initView(){
        //名字
        num=(EditText)findViewById(R.id.num);
        //第一个问题
        num1 = (RadioGroup) findViewById(R.id.num1);
        num1_1 = (RadioButton) findViewById(R.id.num1_1);
        num1_2 = (RadioButton) findViewById(R.id.num1_2);
        //第二题
        num2 = (RadioGroup) findViewById(R.id.num2);
        num2_1 = (RadioButton) findViewById(R.id.num2_1);
        num2_2 = (RadioButton) findViewById(R.id.num2_2);
        num2_3 = (RadioButton) findViewById(R.id.num2_3);
        //第三题
        num3 = (RadioGroup) findViewById(R.id.num3);
        num3_1 = (RadioButton) findViewById(R.id.num3_1);
        num3_2 = (RadioButton) findViewById(R.id.num3_2);
        //第四题
        num4_1 = (CheckBox)findViewById(R.id.num4_1);
        num4_2 = (CheckBox)findViewById(R.id.num4_2);
        num4_3 = (CheckBox)findViewById(R.id.num4_3);
        num4_4 = (CheckBox)findViewById(R.id.num4_4);
        num4_5 = (CheckBox)findViewById(R.id.num4_5);
        num4_6 = (CheckBox)findViewById(R.id.num4_6);
        num4_7 = (CheckBox)findViewById(R.id.num4_7);
        //第五题建议
        num5=(EditText)findViewById(R.id.num5);
        tijiao = (Button) findViewById(R.id.tijiao);
        tuichu = findViewById(R.id.tuichu);
        tijiao.setOnClickListener(this);
        tuichu.setOnClickListener(this);

        num1.setOnCheckedChangeListener(this);
        num2.setOnCheckedChangeListener(this);
        num3.setOnCheckedChangeListener(this);

        num4_1.setOnCheckedChangeListener(this);
        num4_2.setOnCheckedChangeListener(this);
        num4_3.setOnCheckedChangeListener(this);
        num4_4.setOnCheckedChangeListener(this);
        num4_5.setOnCheckedChangeListener(this);
        num4_6.setOnCheckedChangeListener(this);
        num4_7.setOnCheckedChangeListener(this);
        mainConsume = new ArrayList<String>();

    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        int checkboxId=buttonView.getId();
        switch (checkboxId){
            case R.id.num4_1:mainConsume.add(num4_1.getText().toString());
            Toast.makeText(this,"你选择了"+num4_1.getText().toString(),Toast.LENGTH_LONG).show(); break;
            case R.id.num4_2:mainConsume.add(num4_2.getText().toString());
            Toast.makeText(this,"你选择了"+num4_2.getText().toString(),Toast.LENGTH_LONG).show(); break;
            case R.id.num4_3:mainConsume.add(num4_3.getText().toString());
                Toast.makeText(this,"你选择了"+num4_3.getText().toString(),Toast.LENGTH_LONG).show(); break;
            case R.id.num4_4:mainConsume.add(num4_4.getText().toString());
                Toast.makeText(this,"你选择了"+num4_4.getText().toString(),Toast.LENGTH_LONG).show(); break;
            case R.id.num4_5:mainConsume.add(num4_5.getText().toString());
                Toast.makeText(this,"你选择了"+num4_5.getText().toString(),Toast.LENGTH_LONG).show(); break;
            case R.id.num4_6:mainConsume.add(num4_6.getText().toString());
                Toast.makeText(this,"你选择了"+num4_6.getText().toString(),Toast.LENGTH_LONG).show(); break;
            case R.id.num4_7:mainConsume.add(num4_7.getText().toString());
                Toast.makeText(this,"你选择了"+num4_7.getText().toString(),Toast.LENGTH_LONG).show(); break;

        }
    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId){
            case R.id.num1_1:daan1 = num1_1.getText().toString();
                Toast.makeText(this,"你选择了"+num1_1.getText().toString(),Toast.LENGTH_LONG).show(); break;
            case R.id.num1_2:daan1 = num1_2.getText().toString();
                Toast.makeText(this,"你选择了"+num1_2.getText().toString(),Toast.LENGTH_LONG).show(); break;
            case R.id.num2_1:daan2 = num2_1.getText().toString();
                Toast.makeText(this,"你选择了"+num2_1.getText().toString(),Toast.LENGTH_LONG).show(); break;
            case R.id.num2_2:daan2 = num2_2.getText().toString();
                Toast.makeText(this,"你选择了"+num2_2.getText().toString(),Toast.LENGTH_LONG).show(); break;
            case R.id.num2_3:daan2 = num2_3.getText().toString();
                Toast.makeText(this,"你选择了"+num2_3.getText().toString(),Toast.LENGTH_LONG).show(); break;
            case R.id.num3_1:daan3 = num3_1.getText().toString();
                Toast.makeText(this,"你选择了"+num3_1.getText().toString(),Toast.LENGTH_LONG).show(); break;
            case R.id.num3_2:daan3 = num3_2.getText().toString();
                Toast.makeText(this,"你选择了"+num3_2.getText().toString(),Toast.LENGTH_LONG).show(); break;
        }
    }
    @Override
    public void onClick(View v) {
        if(v.getId()==R.id.tijiao){
            String sugg=String.valueOf(num5.getText().toString().trim());
            String sugg0=String.valueOf(num.getText().toString().trim());
            if(daan1==null||daan2==null||daan3==null)
                Toast.makeText(this,"你有未填写的项目！",Toast.LENGTH_SHORT).show();
            else {
                Intent it=new Intent(this,zongjie.class);
                Bundle bundle=new Bundle();
                bundle.putString("daan1",daan1);
                bundle.putString("daan2",daan2);
                bundle.putString("daan3",daan3);
                bundle.putStringArrayList("mainConsume",(ArrayList<String>) mainConsume);
                bundle.putString("sugg", sugg);
                bundle.putString("sugg0",sugg0);
                it.putExtras(bundle);
                startActivity(it);
            }
        }else if(v.getId()==R.id.tuichu){
            this.finish();
        }
    }

}    
    
    
    
    
    
    
    











